package com.open4cn.simulator.connect.com.listenner;

import com.open4cn.simulator.core.connector.ConnectStatus;
import com.open4cn.simulator.core.connector.serialport.SerialPortChannel;
import com.open4cn.simulator.core.connector.serialport.SerialPortOpenListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author yinxiaopeng
 * @version 1.0.0
 * @company 致景科技
 * @department 飞梭BU/研发
 * @description
 * @Email yinxiaopeng@zj.tech
 * @date 2022-06-11 23:26
 */
public class ConnectStatusListener implements SerialPortOpenListener {
    private Logger logger = LoggerFactory.getLogger(this.getClass());

    private ConnectStatus connectStatus;

    public ConnectStatusListener(ConnectStatus connectStatus) {
        this.connectStatus = connectStatus;
    }

    @Override
    public void operationComplete(SerialPortChannel serialPortChannel) {
        if (null != serialPortChannel) {
            connectStatus.beConnect();
        } else {
            connectStatus.beFail();
        }
    }
}
